#include "CConsoleLogger.h"
#include <iostream>
#include <fstream>
#include <string>
#include "CUtil.h"

bool CConsoleLogger::boolConsoleLog;
char CConsoleLogger::ConsoleLogFile[1024];

CConsoleLogger::CConsoleLogger(void)
{
}

CConsoleLogger::~CConsoleLogger(void)
{
}

void CConsoleLogger::init(void) {
	boolConsoleLog = false;
	memset(ConsoleLogFile, 0, 1024);
	CUtil::getINIstring("configure.ini", "SERVER", "CONSOLELOG", ConsoleLogFile);
	if(ConsoleLogFile[0] > 0x00) {
		boolConsoleLog = true;
	}
}
void CConsoleLogger::Out(char * text)
{
	if(boolConsoleLog)
	{
		std::ofstream LogFileHandle;
		LogFileHandle.open(ConsoleLogFile, std::ios::out | std::ios::app);
		LogFileHandle << text << "\n";
		LogFileHandle.close();
	}
}

void CConsoleLogger::Out(char * timestamp, char * text)
{
	char strout[1024];
	memset(strout, 0, 1024);
	sprintf(strout, "%s %s", timestamp, text);
	CConsoleLogger::Out(strout);
}

void CConsoleLogger::setStatus(bool boolStatus) {
	boolConsoleLog = boolStatus;
}

bool CConsoleLogger::getStatus(void) {
	return boolConsoleLog;
}
